/**
 * 系统通知消息类
 */
class Notification {
	/**
	 * 构造函数
	 * @param {Object} options - 通知选项
	 * @param {string} options.userId - 接收用户ID
	 * @param {string} options.type - 通知类型
	 * @param {string} options.title - 通知标题
	 * @param {Object} options.content - 通知内容对象
	 * @param {string} [options.senderId=null] - 发送方ID
	 * @param {string} [options.senderName='系统通知'] - 发送方名称
	 * @param {string} [options.relatedId=null] - 关联业务ID
	 */
	constructor(options) {
		const {
			userId,
			type,
			title,
			content,
			senderId = null,
			senderName = '系统通知',
			senderNicPic,
			relatedId = null
		} = options;

		if (!userId || !type || !title || !content) {
			throw new Error('创建通知失败：userId, type, title, content 为必填项');
		}

		this.userId = userId;
		this.senderId = senderId;
		this.senderName = senderName;
		this.type = type;
		this.title = title;
		this.content = content;
		this.isRead = false;
		this.senderNicPic=senderNicPic
		this.createTime = Date.now();
		this.relatedId = relatedId;
	}

	/**
	 * 将通知对象转换为可存入数据库的普通对象
	 * @returns {Object}
	 */
	toObject() {
		return {
			userId: this.userId,
			sendUserId: this.senderId,
			senderName: this.senderName,
			type: this.type,
			title: this.title,
			content: this.content,
			isRead: this.isRead,
			createTime: this.createTime,
			relatedId: this.relatedId,
		};
	}


	// 可以在这里定义一些静态方法，用于生成特定类型的通知
	static createFriendApplyNotification(fromUser, toUserId, applyMsg) {
		return new Notification({
			userId: toUserId,
			type: 'friend_apply',
			title: '好友申请',
			content: {
				applyMsg
			},
			senderId: fromUser.userId,
			senderName: fromUser.nickName,
			
		});
	}
}

module.exports = Notification;